package main

import "fmt"

const PI = 3.14

type shaper interface {
	CalArea()
	GetArea() float64
}

type round struct {
	radius float64
	area   float64
}

func (r *round) CalArea() {
	area := PI * r.radius * r.radius
	r.area = area
}

func (r *round) GetArea() float64 {
	return r.area
}

type triangle struct {
	height float64
	bottom float64
	area   float64
}

func (t *triangle) CalArea() {
	area := t.bottom * t.height / 2
	t.area = area
}

func (t *triangle) GetArea() float64 {
	return t.area
}

type rectangle struct {
	height float64
	width  float64
	area   float64
}

func (r *rectangle) CalArea() {
	area := r.height * r.width
	r.area = area
}

func (r *rectangle) GetArea() float64 {
	return r.area
}

func main() {
	var s shaper

	// 求圆的面积
	r1 := new(round)
	r1.radius = 2.1
	s = r1
	s.CalArea()
	fmt.Println("the area of round: ", s.GetArea())

	// 求三角形的面积
	tr1 := new(triangle)
	tr1.bottom = 2.5
	tr1.height = 3.0
	s = tr1
	s.CalArea()
	fmt.Println("the area of triangle: ", s.GetArea())

	// 求长方形的面积
	t1 := new(rectangle)
	t1.width = 2.0
	t1.height = 3.0
	s = t1
	s.CalArea()
	fmt.Println("the area of rectangle: ", s.GetArea())
}
